<template>
	<loading v-if="isLoading" style="height: 70vh;"></loading>
	<view class="empty" v-else-if="!goodInfo">
		<image
			src="https://sgymv1.oss-cn-beijing.aliyuncs.com/sgym/avatar/admin/2025/02/a0c4966b-11af-4c87-93aa-359f9c03d89f83ee61eba8e363790692eb5fd8a98de7.png"
			mode="widthFix"></image>
		<text>这里空空荡荡，啥也没有留下</text>
	</view>
	<view v-else>
		<tn-form :model="goodInfo" ref="formRef" label-position="top">
			<tn-form-item label="编码/条码">
				<tn-input v-model="goodInfo.goods_code" placeholder="请输入编码/条码" clearable />
			</tn-form-item>
			<tn-form-item label="规格/型号">
				<tn-input v-model="goodInfo.goods_spec" placeholder="请输入规格/型号" clearable />
			</tn-form-item>
			<tn-form-item label="商品产地">
				<tn-input v-model="goodInfo.goods_origin" placeholder="请输入商品产地" clearable />
			</tn-form-item>
			<tn-form-item label="商品材质">
				<tn-input v-model="goodInfo.goods_material" placeholder="请输入商品材质" clearable />
			</tn-form-item>
			<tn-form-item label="保质期">
				<tn-input v-model="goodInfo.goods_day" placeholder="请输入保质期" clearable />
			</tn-form-item>
			<tn-form-item label="备注">
				<tn-input type="textarea" v-model="goodInfo.goods_remark" placeholder="请输入备注" clearable />
			</tn-form-item>
		</tn-form>
		<view class="tn-flex-center">
			<tn-button size="lg" width="80vw" height="80" font-size="26" @click="submitForReview">确定修改</tn-button>
		</view>
	</view>
</template>

<script setup>
	import {
		onMounted,
		ref,
	} from 'vue'
	import {
		getGoodsInfoApi,
	} from "@/request/worktop/index.js"
	import {
		base_url,
		domain_name,
		uploadHandle
	} from "@/request/index.js"

	onMounted(() => {
		goodInfo.value.id = props.userId
		getGoodsInfo()
	})

	const props = defineProps(['userId'])

	const isLoading = ref(true)
	const goodInfo = ref({
		id: 0,
		goods_code: '',
		goods_spec: '',
		goods_origin: '',
		goods_material: '',
		goods_day: '',
		goods_remark: ''
	})

	// 获取商品详情
	const getGoodsInfo = (type = '') => {
		getGoodsInfoApi(goodInfo.value, type).then(res => {
			if (res.code == 0) {
				goodInfo.value = res.data
			}
		}).catch(err => {
			uni.showToast({
				title: err.message,
				icon: 'none'
			})
		}).finally(() => {
			setTimeout(() => {
				isLoading.value = false
			}, 500)
		})
	}
	// 确定修改配送商信息
	const submitForReview = () => {
		getGoodsInfoApi(goodInfo.value, 'edit').then(res => {
			if (res.code == 0) {
				uni.showToast({
					title: res.message
				})
			}
		}).catch(err => {
			uni.showToast({
				title: err.message,
				icon: 'none'
			})
		})
	}
</script>

<style scoped lang="scss">
</style>